// script for operating a toggle pushbutton switch
var switch_off = new Image();
switch_off.src = "red_button_up.gif";
var switch_on = new Image();
switch_on.src = "red_button_dn.gif";
var switch_state = 0;
var output_no = 0;
var this_day = new Date();
var this_second = this_day.getSeconds();
var rb_value = 100;
var led_speed = (this_second+10);
// trying hard to get a random number
//javascript random function works only in UNIX so i am trying above

function spin_it(){
//
if (switch_state == 0 )
{
switch_state=1;
document.images.red_btn.src = switch_on.src;
this_day = new Date();
this_second = this_day.getSeconds();
led_speed = (this_second+10);
run_led();
}
//end
}

//script for LEDs
var gled_off = new Image();
gled_off.src = "green_off.gif";
var gled_on = new Image();
gled_on.src = "green_on.gif";
var rled_off = new Image();
rled_off.src = "red_off.gif";
var rled_on = new Image();
rled_on.src = "red_on.gif";
var yled_off = new Image();
yled_off.src = "yellow_off.gif";
var yled_on = new Image();
yled_on.src = "yellow_on.gif";



function run_led() {
counter_run(); //this is the positive edge i think?, hence advance counter
window.setTimeout('turn_off()',led_speed);
//end
}


function turn_on() {
counter_run(); //this is the positive edge i think?, hence advance counter
window.setTimeout('turn_off()',led_speed);
//end
}

function turn_off() {
if (led_speed < rb_value)
{
window.setTimeout('turn_on()',led_speed);
led_speed = led_speed + 3 ;
}
else
{
document.images.red_btn.src = switch_off.src;
switch_state = 0;
led_speed = 0.1*rb_value;
output_no = 0 //reset counter
}
//end
}

//the below code for a pot for Rb resistor
function dec_rb(speedy) {
if (rb_value > 60) {
rb_value = rb_value-(1*speedy);
}
document.rb_set.rb_dsp.value = rb_value
//end
}

function inc_rb(speedy) {
if (rb_value < 300) {
rb_value = rb_value+(1*speedy);
}
document.rb_set.rb_dsp.value = rb_value
//end
}

//the code for counter

function counter_run() {
var current_led = "q" + output_no + "_led";
var previous_led = "q" + (output_no-1) + "_led";
if (output_no < 3){
if  (output_no == 0){
document.images[current_led].src = gled_on.src;
}
if  (output_no == 1){
document.images[current_led].src = rled_on.src;
document.images[previous_led].src = gled_off.src;
}
if  (output_no == 2){
document.images[current_led].src = yled_on.src;
document.images[previous_led].src = rled_off.src;
}
output_no = output_no+1; // increment counter
}
else
{
document.images[previous_led].src = yled_off.src;
output_no = 0; //reset counter
counter_run();
}
//end
}
























